#ifndef COLLECT_H
#define COLLECT_H

#include <QLineSeries>
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QTimer>
#include <QSplineSeries>
#include <QChart>
class Collect : public QObject
{
    Q_OBJECT
public:
    explicit Collect(QObject *parent=nullptr);
    Collect(QtCharts::QSplineSeries *series,QMutex* collectLock,QtCharts::QChart *chart,int saveMax,QObject *parent=nullptr);
    ~Collect();
    void setIsAutomaticMode(bool r);
    void setIsCloudAndLocalSave(bool isCloud,bool isLocal);
    //void setCurrentCollectNumber(int n);
    //void addCurrentCollectNumber();
public slots:
    void isStartCollect(int refreshTimeMs,bool r);
    void collectData();
    void init();
    void clearData();
signals:
    void paintingChart();
private:
    QThread *myThread=nullptr;
    QTimer *collectTimer=nullptr;
    int collectIntervalMs=50;
    QtCharts::QSplineSeries *series=nullptr;
    QtCharts::QChart *chart=nullptr;
    QMutex* collectLock=nullptr;
    int saveMax=0;
    int refreshTimeMs;//界面刷新时间

    QList<int>keys;
    QList<float>values;
    QList<QString>times;
    int counter = 1;
    int refreshCounter=1;
    int adc_cont=0;
    //int currentCollectNumber=1;
    bool isAutomaticMode=false;//默认手动
    bool isCloudSave=false;//默认不上传服务器
    bool isLocalSave=false;//默认不保存本地
};

#endif // COLLECT_H
